package com.clps.cn;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.Test;

import java.util.List;

/**
 * c查询用户的任务表
 */
public class ActiviteTaskQuery {

    public static void main(String[] args) {

        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();

        TaskService taskService = defaultProcessEngine.getTaskService();

        //03：根据流程定义的key得到任务表
        List<Task> list = taskService.createTaskQuery()
                .processDefinitionKey("holiday")
                .taskAssignee("zhangsan")
                .list();
        //任务列表
        for (Task task : list) {
            System.out.println("task.getProcessInstanceId() = " + task.getProcessInstanceId());
            System.out.println("task.getId() = " + task.getId());
            System.out.println("task.getAssignee() = " + task.getAssignee());
            System.out.println("task.getName() = " + task.getName());

        }
    }

    @Test
    public void queryLisiMessage() {
        //得到ProcessEnginesr对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //得到taskservice对象
        TaskService taskService = defaultProcessEngine.getTaskService();
        //根据定义的key,负责assignee来实现当前用户的任务查询列表
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("holiday")
                .taskAssignee("lisi")
                .singleResult();

        //04,任务列表的展示
        System.out.println("task.getProcessInstanceId() = " + task.getProcessInstanceId());
        System.out.println("task.getId() = " + task.getId());
        System.out.println("task.getAssignee() = " + task.getAssignee());
        System.out.println("task.getName() = " + task.getName());
    }


    /**
     * 总经理审批查询
     */
    @Test
    public  void  queryWangwuMessage(){
        //01:得到processEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();
        //02:得到taskService对象
        TaskService taskService = defaultProcessEngine.getTaskService();
        //根据定义的key,负责assignee来实现用户的任务查询列表
        Task task = taskService.createTaskQuery()
                .processDefinitionKey("holiday")
                .taskAssignee("wangwu")
                .singleResult();
        //04；任务列表的打印
        System.out.println("task.getProcessInstanceId() = " + task.getProcessInstanceId());
        System.out.println("task.getId() = " + task.getId());
        System.out.println("task.getAssignee() = " + task.getAssignee());
        System.out.println("task.getName() = " + task.getName());



        /**
         * task.getProcessInstanceId() = 2501
         * task.getId() = 10002
         * task.getAssignee() = wangwu
         * task.getName() = 总经理审批
         */
    }

}
